package com.hc.testaudio.deletea.test1.ui;

import android.media.MediaExtractor;
import android.media.MediaFormat;
import android.media.audiofx.Visualizer;
import android.os.Bundle;
import android.util.Log;

import com.hc.testaudio.R;
import com.hc.testaudio.deletea.ui.BaseActivity;
import com.yc.yclibx.file.YcFileUtils;

import java.io.File;
import java.io.IOException;

/**
 *
 */
public class MediaExtractorActivity extends BaseActivity {

    private MediaExtractor mMediaExtractor;
    private final String TAG = "MediaExtractorActivity";

    @Override
    protected int getLayoutId() {
        return R.layout.media_extractor_activity;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        findViewById(R.id.mediaExtractorStartBtn).setOnClickListener(v -> track());

    }
    private void visualizer(){
        Visualizer visualizer = new Visualizer(0);
//        visualizer.getWaveForm();
    }
    private void track() {
        mMediaExtractor = new MediaExtractor();
        try {
            mMediaExtractor.setDataSource(YcFileUtils.SD_PATH + File.separator + "hz1000.mp3");
            int count = mMediaExtractor.getTrackCount();//获取轨道数量
            for (int i = 0; i < count; i++) {
                MediaFormat mediaFormat = mMediaExtractor.getTrackFormat(0);
                Log.e(TAG, i + "编号通道格式 = " + mediaFormat.getString(MediaFormat.KEY_MIME));
                String mimeFormat = mediaFormat.getString(MediaFormat.KEY_MIME);//获取MIME格式内容
                Log.e(TAG, "mediaExtractor: 获取MIME格式内容=" + mimeFormat);
                int maxByteCount = mediaFormat.getInteger(MediaFormat.KEY_MAX_INPUT_SIZE);//获取视频缓存输出的最大大小
                Log.e(TAG, "mediaExtractor: 获取MIME格式内容=" + mimeFormat);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
